import 'package:image_picker/image_picker.dart';

class CameraTools {
  // 静态变量存储单例
  static final CameraTools _instance = CameraTools._internal();
  // 静态方法获取单例实例
  factory CameraTools() => _instance;
  // 私有构造函数，确保只能通过工厂方法获取实例
  CameraTools._internal();

  // 静态的 _picker 变量，确保只会初始化一次
  final ImagePicker _picker = ImagePicker();

  // 打开相机
  Future<void> showCamera({
    bool? cropping,
    // ValueChanged<String>? onChanged,
  }) async {
    try {
      final XFile? file = await _picker.pickImage(source: ImageSource.camera);
      if (file != null) {
        if (cropping == true) {
          // await _cropImage(path: file.path, onChanged: onChanged);
        } else {
          // if (onChanged != null) {
          //   onChanged(file.path);
          // }
        }
      } else {
        // if (onChanged != null) {
        //   onChanged('');
        // }
      }
    } catch (e) {
      // if (onChanged != null) {
      //   onChanged('');
      // }
      // print('图片选择出错: $e');
    }
  }
}
